package com.snow.useviewdemo.function;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.snow.useviewdemo.R;
import com.snow.useviewdemo.base.BaseActivity;
import com.snow.useviewdemo.databinding.CustomViewEffectTestBinding;
import com.snow.useviewdemo.databinding.LoadingViewTestBinding;
import com.snow.useviewdemo.util.LogUtils;
import com.snow.useviewdemo.view.CheckSwitchView;
import com.snow.useviewdemo.view.DashboardView;

import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;

/**
 * author : zyt
 * e-mail : 632105276@qq.com
 * date   : 2020-04-10
 * desc   :自定义view显示效果
 */
public class CustomViewEffectTestActivity extends BaseActivity<CustomViewEffectTestBinding> {
    @Override
    protected int getLayoutId() {
        return R.layout.custom_view_effect_test;
    }

    @Override
    protected void setViewData(Bundle savedInstanceState) {
        initViewData();
    }

    private void initViewData() {
        mBinding.loadingView.setAnimationSpeed(0.8f);

        mBinding.checkSwitchView.setSwitchColor(Color.parseColor("#1971FF"), Color.parseColor("#C9CDD4"));
        mBinding.checkSwitchView.setOnCheckedChangeListener((view, isChecked) -> {

        });

        mBinding.linearProgressBarView.setProgress(60, 1000);
        initDashboardData();
    }

    private void initDashboardData() {
        float[] progressDadaList = {3, 15, 33, 50, 60, 75, 83, 120, 180, 240, 290, 330, 370, 430, 510, 620, 710};
        mBinding.dashboardView.setDashboardProgressListener(progressValue -> {
            mBinding.progressTv.setText(progressValue);
        });
        mBinding.dashboardView.setProgressColor(Color.parseColor("#0285f0"), Color.parseColor("#990285f0"));
        final float[] value = new float[1];
        Observable.intervalRange(0, 15, 0, 1, TimeUnit.SECONDS)
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(aLong -> {
                    int position = (int) (Math.random() * progressDadaList.length);
                    value[0] = progressDadaList[position];
                    LogUtils.d("CustomViewEffectTest--->>>   value:" + value[0]);
                    mBinding.dashboardView.setProgress(value[0]);
                })
                .doOnComplete(() -> {
                    mBinding.dashboardView.resetProgress();
//                    mBinding.dashboardView.setProgress(value[0], true);
                }).subscribe();
    }
}
